#include <StormPort.h>
#include <StormLib.h>
#include "MPQProvider.h"
#include "StormLib.h"

using namespace CEGUI;

MPQProvider::MPQProvider( const String& sDataDir )
{
	m_sDataDir = sDataDir;
	SFileOpenArchive((TCHAR*)m_sDataDir.c_str(), 0, STREAM_FLAG_READ_ONLY, &m_hMpq);
}

void MPQProvider::loadRawDataContainer( const String& filename, RawDataContainer& output, const String& resourceGroup )
{
	String fullpath = getFinalFilename(filename, resourceGroup);
	String prefix("D:\\Xzh\\NavisSVN\\Resource\\");

	fullpath = fullpath.substr(prefix.length());


	HANDLE hFile = NULL;
	SFileOpenFileEx(m_hMpq, fullpath.c_str(), SFILE_OPEN_FROM_MPQ, &hFile);
	if (NULL !=m_hMpq && NULL!=hFile)
	{
		DWORD dwSize=SFileGetFileSize(hFile, NULL);
		output.setSize(dwSize);
		output.setData(new uint8[dwSize]);
		SFileReadFile(hFile, output.getDataPtr(), dwSize, NULL, NULL);
	}
}

